package com.ruoyi.numericalselection.service.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.numericalselection.domain.GmInventory;
import com.ruoyi.numericalselection.domain.dao.GmInventoryDao;
import com.ruoyi.numericalselection.domain.dao.GmTypeDao;
import com.ruoyi.numericalselection.mapper.GmInventoryMapper;
import com.ruoyi.numericalselection.service.IGmInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-29
 */
@Service
public class GmInventoryServiceImpl implements IGmInventoryService {
    @Autowired
    private GmInventoryMapper gmInventoryMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public GmInventory selectGmInventoryById(Long id) {
        return gmInventoryMapper.selectGmInventoryById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param gmInventory 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<GmInventory> selectGmInventoryList(GmInventory gmInventory) {
        return gmInventoryMapper.selectGmInventoryList(gmInventory);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param gmInventory 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertGmInventory(GmInventory gmInventory) {
        String gameId = IdUtils.randomUUID() + System.currentTimeMillis();
        gmInventory.setGameId(gameId);
        return gmInventoryMapper.insertGmInventory(gmInventory);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param gmInventory 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateGmInventory(GmInventory gmInventory) {
        return gmInventoryMapper.updateGmInventory(gmInventory);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteGmInventoryByIds(Long[] ids) {
        return gmInventoryMapper.deleteGmInventoryByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteGmInventoryById(Long id) {
        return gmInventoryMapper.deleteGmInventoryById(id);
    }


    @Override
    public List<GmInventory> selectAppGmInventoryList(GmInventory gmInventory) {
        return gmInventoryMapper.selectAppGmInventoryList(gmInventory);
    }



    @Override
    public GmInventoryDao selectJoinById(Long id) {
        GmInventoryDao gmInventoryDao = gmInventoryMapper.selectJoinById(id);
        if (gmInventoryDao.getFirstPicture() != null && !gmInventoryDao.getFirstPicture().isEmpty()) {
            gmInventoryDao.setFirstPictures(Collections.singletonList(gmInventoryDao.getFirstPicture()));
        }
        if (gmInventoryDao.getDetailedDiagram() != null && !gmInventoryDao.getDetailedDiagram().isEmpty()) {
            String[] split = gmInventoryDao.getDetailedDiagram().split(",");
            List<String> stringList = Arrays.asList(split);
            gmInventoryDao.setDetailedDiagrams(stringList);
        }
        return gmInventoryDao;
    }

    @Override
    public List<GmInventory> gmAccList(GmInventoryDao gmInventory) {
        return gmInventoryMapper.gmAccList(gmInventory);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateType(GmTypeDao gmTypeDao) {
        GmInventory gmInventory = gmInventoryMapper.selectGmInventoryById(gmTypeDao.getId());
        if (gmInventory ==null){
            throw  new BaseException("查询失败");
        }
        gmInventory.setIsRecommend(gmTypeDao.getIsRecommend());
        gmInventory.setIsItDisplayed(gmTypeDao.getIsItDisplayed());
        gmInventory.setLogicalDeletion(gmTypeDao.getLogicalDeletion());
        return gmInventoryMapper.updateGmInventory(gmInventory);
    }

    @Override
    public int selectCount(Long id) {
        return gmInventoryMapper.selectCount(id);
    }

    @Override
    public int updateGmIdByDelect(Long id) {
        return gmInventoryMapper.updateGmIdByDelect(id);
    }
}
